package com.zmht.beike.biz.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.zmht.beike.biz.CAreaContentBiz;
import com.zmht.beike.core.BaseBizImpl;
import com.zmht.beike.po.TCareacontent;

public class CAreaContentBizImpl extends BaseBizImpl implements CAreaContentBiz {
	/*
	 * (non-Javadoc)
	 * @see com.zmht.beike.biz.CAreaContentBiz#saveLinyuContent(com.zmht.beike.po.TCareacontent)
	 */
	public Integer saveLinyuContent(TCareacontent careacontent) {
		/**
		 * ���浱ǰ���󲢷���
		 */
		return (Integer)this.getCareaContentDAO().saveObj(careacontent);
		
	}
	public List findAreaContent(String sessionId, Integer type,int startIndex,int pageSize) {
		return this.getCareaContentDAO().findByPage("from TCareacontent tc where tc.areaType='"+type+"' and tc.caimId is null  and tc.caimId = null ", startIndex, pageSize);
		//return this.getCareaContentDAO().findByHQLObj("from TCareacontent tc where tc.areaType='"+type+"' and tc.sessionID='"+sessionId+"'");
	}
	/*
	 * (non-Javadoc)
	 * @see com.zmht.beike.biz.CAreaContentBiz#findAreaContentTotal(java.lang.String, java.lang.Integer)
	 */
	public int findAreaContentTotal(String sessionId, Integer type) {
		return this.getCareaContentDAO().findByHQLObj("from TCareacontent tc where tc.areaType='"+type+"' and tc.caimId is null ").size();
		
	}
	public boolean delTCareacontent(Serializable careacontent) {
		try{
			this.getCareaContentDAO().deleteObj(careacontent);
		}catch(Exception e){
			return false;
		}
		return true;
	}
	public TCareacontent findByID(Serializable id) {
		
		return (TCareacontent)this.getCareaContentDAO().findById(TCareacontent.class, id);
	}
	/**
	 * update time
	 * 
	 */
	public boolean upTCareacontent(TCareacontent careacontent) {
		try{
			this.getCareaContentDAO().updateObj(careacontent);
		}catch(Exception e){
			return false;
		}
		return true;
	}
	public static void main(String [] args){
		ApplicationContext cxt;
		cxt = new ClassPathXmlApplicationContext(new String[]{"spring/spring.xml","spring/spring_dao.xml","spring/spring_beike.xml",});
		CAreaContentBiz biz = (CAreaContentBizImpl)cxt.getBean("careaContentBizTag"); 
		
		TCareacontent content = new TCareacontent();
		content.setAreaContent("������");
		content.setAreaType(new Integer(1));
		
		Integer id = biz.saveLinyuContent(content);
		System.out.println("------------"+id);
	}
	public List findByHQL(String hql) {
		return this.getCareaContentDAO().findByHQLObj(hql);
	
	}
	/*
	 * 根据目标id 和 领域类型获得结果 以及老师id
	 * (non-Javadoc)
	 * @see com.zmht.beike.biz.CAreaContentBiz#findAreaContentEdit(java.lang.Integer, java.lang.Integer, int, int)
	 */
	public List findAreaContentEdit(Integer targetId,Integer teacherId, Integer type,
			int startIndex, int pageSize) {
			String hql = "from TCareacontent t where t.teacherId="+teacherId+" and t.caimId="+targetId+" and t.areaType="+type;
		return this.getCareaContentDAO().findByPage(hql, startIndex, pageSize);
	}
	/*
	 * 查询记录总数
	 * (non-Javadoc)
	 * @see com.zmht.beike.biz.CAreaContentBiz#findAreaContentEditTotal(java.lang.Integer, java.lang.Integer, java.lang.Integer, int, int)
	 */	
	public int findAreaContentEditTotal(Integer targetId, Integer teacherId,
			Integer type) {
			String hql = "from TCareacontent t where t.teacherId="+teacherId+" and t.caimId="+targetId+" and t.areaType="+type;
		return this.getCareaContentDAO().findByPageAmount(hql);//.findByPage(hql, startIndex, pageSize);
	}
	
	
	

}
